#!/usr/bin/env python3
# Created by han on 2016/7/4
import os,sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from module import public
from module import my_client
from conf import db_conf
IP = db_conf.server_info[0]
PORT = db_conf.server_info[1]

def client_main():
    while True:
        menu_list = ["登陆","注册"]
        user_chose = public.user_chose(*menu_list)
        if not user_chose:
            continue
        elif user_chose == "b":
            break
        elif user_chose == "1":             #登陆
            while True:
                ret = public.login()        #登陆，并获取用户文件中的信息
                if not ret:                 #如果返回值为假
                    break                #用户名密码有误
                elif ret == "reg":          #如果返回为reg，代表用户没有登录
                    break                   #没有注册过不能登陆
                else:
                    user_connect = my_client.myclient(IP, PORT, ret["name"], ret["user_size"])
                    user_connect.cmd()
        elif user_chose == "2":         #注册
            while True:
                reg_ret = public.register()
                if not reg_ret:
                    continue
                # print(reg_ret,type(reg_ret))
                user = my_client.myclient(IP, PORT)
                user.client_register(reg_ret)
                msg = "register success"
                public.color_msg(32, msg, 40)
                break
